﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

/// <summary>
/// Summary description for MATHANG
/// </summary>
public class MATHANG
{
    public int MaSP { get; set; }
    public string TenSP{ get; set; }
    public string Hinhanh { get; set; }
    public string Gia { get; set; }
    public string Ngaynhap { get; set; }
    public string Hang { get; set; }
    public string Mota { get; set; }
    AccessData ac = new AccessData();
	public MATHANG()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public void Insert(MATHANG SP)
    {
        SqlConnection con = ac.GetConnect();
        con.Open();
        SqlCommand cmd = new SqlCommand("SP_SanPham", con);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.Parameters.Add("@MaSP", System.Data.SqlDbType.NVarChar).Value = SP.MaSP;
        cmd.Parameters.Add("@TenSP", System.Data.SqlDbType.NVarChar).Value = SP.TenSP;
        cmd.Parameters.Add("@Hinhanh", System.Data.SqlDbType.NVarChar).Value = SP.Hinhanh;
        cmd.Parameters.Add("@Gia", System.Data.SqlDbType.NVarChar).Value = SP.Gia;
        cmd.Parameters.Add("@Ngaynhap", System.Data.SqlDbType.DateTime).Value = SP.Ngaynhap;
        cmd.Parameters.Add("@Hang", System.Data.SqlDbType.NVarChar).Value = SP.Hang;
        cmd.Parameters.Add("@Mota", System.Data.SqlDbType.NVarChar).Value = SP.Mota;
        cmd.ExecuteNonQuery();
        cmd.Dispose();
        con.Close();
    }
    public void Update(MATHANG SP)
    {
        SqlConnection con = ac.GetConnect();
        con.Open();
        SqlCommand cmd = new SqlCommand("Up_SanPham", con);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.Parameters.Add("@MaSP", System.Data.SqlDbType.NVarChar).Value = SP.MaSP;
        cmd.Parameters.Add("@TenSP", System.Data.SqlDbType.NVarChar).Value = SP.TenSP;
        cmd.Parameters.Add("@Hinhanh", System.Data.SqlDbType.NVarChar).Value = SP.Hinhanh;
        cmd.Parameters.Add("@Gia", System.Data.SqlDbType.NVarChar).Value = SP.Gia;
        cmd.Parameters.Add("@Ngaynhap", System.Data.SqlDbType.DateTime).Value = SP.Ngaynhap;
        cmd.Parameters.Add("@Hang", System.Data.SqlDbType.NVarChar).Value = SP.Hang;
        cmd.Parameters.Add("@Mota", System.Data.SqlDbType.NVarChar).Value = SP.Mota;
        cmd.ExecuteNonQuery();
        cmd.Dispose();
        con.Close();
    }
    public void Delete(MATHANG SP)
    {
        SqlConnection con = ac.GetConnect();
        con.Open();
        SqlCommand cmd = new SqlCommand("Xoa_SP", con);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.Parameters.Add("@MaSP", System.Data.SqlDbType.BigInt).Value = SP.MaSP;
        cmd.ExecuteNonQuery();
        cmd.Dispose();
        con.Close();
    }

}
